import {
  select_system_cityAddObj,
  add_system_cityAddObj,
  select_system_cityList,
  delete_system_cityAddObj,
  updateshow_system_cityAddObj,
  add_system_userAddObj,
  update_system_userAddObj,
  delete_system_userAddObj,
  select_system_userAddObj,
  
} from "@/api/system_page.js";
// 系统管理
const state = {
//   commonSeclect: {},
//   systemcityList: {},
  systemcityListItem: {},
  /**
   * 用户管理
   */
  system_userSeclect: {},
  system_userListItem: {}
};

const mutations = {
  //systemcityListItem
  SET_SYSTEMCITYLISTITEM(state, val) {
    state.systemcityListItem = val;
  },
//   // commonSeclect
//   SET_COMMONSELECT(state, val) {
//     state.commonSeclect = val;
//   },
//   //commonList
//   SET_COMMONLIST(state, val) {
//     state.commonList = val;
//   }

    /**
     * 用户管理
     */
    //system_userListItem
    SET_SYSUSERLISTITEM(state, val) {
      state.system_userListItem = val;
    },
    // system_userSeclect
    SET_SYSUSERSELECT(state, val) {
      state.system_userSeclect = val;
    },
};

const actions = {

  /**
   * 城市
   */
  // 添加-查询没有加入得名称
  select_system_cityList({ commit }, val) {
    // 发送请求
    return new Promise((resolve, reject) => {
      select_system_cityList(val)
        .then(res => {
          // 数据列表里面添加数据
          const { data } = res.data;
          resolve(data);
        })
        .catch(err => {
          reject();
        });
    });
  },
  // 添加-查询没有加入得名称
  select_system_cityAddObj({ commit }, val) {
    // 发送请求
    return new Promise((resolve, reject) => {
      select_system_cityAddObj(val)
        .then(res => {
          // 数据列表里面添加数据
          const { data } = res.data;
          resolve(data);
        })
        .catch(err => {
          reject();
        });
    });
  },
  // 添加
  add_system_cityAddObj({ commit }, val) {
    commit("SET_SYSTEMCITYLISTITEM", val);
    return new Promise((resolve, reject) => {
      add_system_cityAddObj(val)
        .then(res => {
          if (res && res.data && res.data.code === "000000") {
            resolve(true);
          } else {
            resolve(false);
          }
        })
        .catch(err => {
          reject(false);
        });
    });
  },
  // 修改显示
  updateshow_system_cityAddObj({ commit }, val) {
    commit("SET_SYSTEMCITYLISTITEM", val);
    return new Promise((resolve, reject) => {
      updateshow_system_cityAddObj(val)
        .then(res => {
          resolve();
        })
        .catch(err => {
          reject();
        });
    });
  },
  // 删除
  delete_system_cityAddObj({ commit }, val) {
    return new Promise((resolve, reject) => {
      delete_system_cityAddObj(val)
        .then(res => {
          if (res && res.data && res.data.code === "000000") {
            resolve(true);
          } else {
            resolve(false);
          }
        })
        .catch(err => {
          reject();
        });
    });
  },
  /**
   * 系统用户管理
   */
      // 添加
      add_system_userAddObj({ commit }, val) {
        commit("SET_SYSUSERLISTITEM", val);
        return new Promise((resolve, reject) => {
          add_system_userAddObj(val)
            .then(res => {
              if (res && res.data && res.data.code === "000000") {
                resolve(true);
              } else {
                resolve(false);
              }
            })
            .catch(err => {
              reject(false);
            });
        });
      },
      // 修改
      update_system_userAddObj({ commit }, val) {
        commit("SET_SYSUSERLISTITEM", val);
        return new Promise((resolve, reject) => {
          update_system_userAddObj(val)
            .then(res => {
              if (res && res.data && res.data.code === "000000") {
                resolve(true);
              } else {
                resolve(false);
              }
            })
            .catch(err => {
              reject();
            });
        });
      },
      // 修改显示
      // updateshow_system_userAddObj({ commit }, val) {
      //   commit("SET_SYSUSERLISTITEM", val);
      //   return new Promise((resolve, reject) => {
      //     updateshow_system_userAddObj(val)
      //       .then(res => {
      //         resolve();
      //       })
      //       .catch(err => {
      //         reject();
      //       });
      //   });
      // },
      // 删除
      delete_system_userAddObj({ commit }, val) {
        return new Promise((resolve, reject) => {
          delete_system_userAddObj(val)
            .then(res => {
              if (res && res.data && res.data.code === "000000") {
                resolve(true);
              } else {
                resolve(false);
              }
            })
            .catch(err => {
              reject();
            });
        });
      },
      // 点击编辑存放的数据
      list_system_userListItem({ commit }, val) {
        commit("SET_SYSUSERLISTITEM", val);
      },
      // 点击查询
      select_system_user({ commit }, val) {
        // 存放查询数据
        commit("SET_SYSUSERSELECT", val);
        // 发送请求
        return new Promise((resolve, reject) => {
          select_system_userAddObj(val)
            .then(res => {
              // 数据列表里面添加数据
              const { data } = res.data;
              resolve(data);
            })
            .catch(err => {
              reject();
            });
        });
      },
};

export default {
  namespaced: true,
  state,
  mutations,
  actions
};
